package com.yidu.verycd_background.controller;

import com.yidu.verycd_background.entity.VerycdComment;
import com.yidu.verycd_background.service.VerycdCommentService;
import org.springframework.web.bind.annotation.*;
import util.BaseMessage;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (VerycdComment)表控制层
 *
 * @author makejava
 * @since 2020-07-27 09:57:00
 */
@RestController
@RequestMapping("verycdComment")
public class VerycdCommentController {
    /**
     * 服务对象
     */
    @Resource
    private VerycdCommentService verycdCommentService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping("selectOne")
    @ResponseBody
    public VerycdComment selectOne(Integer id) {
        return this.verycdCommentService.queryById(id);
    }

    /**
     * 查询全部
     * @param
     * @return
     */
    @RequestMapping("findAll")
    @ResponseBody
    public Map<String,Object> findAll(int page,int limit){

        //查询所有的用户
        List<VerycdComment> list = verycdCommentService.queryAllByLimit(page,limit);
        //查询所有的行数
        int count = verycdCommentService.selectCount();
        Map<String,Object>  map  = new HashMap();
        map.put("data",list);
        map.put("count",count);
        map.put("code",0);
        map.put("msg","");
        return map;

    }

    /**
     *删除
     * @param comId
     * @return
     */
    @RequestMapping("delete")
    @ResponseBody
    public BaseMessage delete( Integer comId){
        System.out.println(comId);
        boolean flag = verycdCommentService.deleteById(comId);
        BaseMessage baseMessage = new BaseMessage();
        if(!flag){
            baseMessage.setState(BaseMessage.ERROR);
            baseMessage.setMsg("删除失败");
        }
        return baseMessage;
    }

    /**
     * 增加
     * @param
     * @return
     */
    @RequestMapping("add")
    @ResponseBody
    public BaseMessage insert(VerycdComment commentVo){
        VerycdComment po = verycdCommentService.insert(commentVo);
        BaseMessage baseMessage = new BaseMessage();
        if(po.getComId()==null){
            baseMessage.setState(BaseMessage.ERROR);
            baseMessage.setMsg("增加用户失败!");
        }
        return baseMessage ;
    }







}